
# 获取proto生成的C++代码
file(GLOB_RECURSE PROTO_FILES ${CMAKE_SOURCE_DIR}/resource/*.proto)
set(PROTO_SRC "")
set(PROTO_HEADER "")
foreach(msg ${PROTO_FILES})
    get_filename_component(PREFIX ${msg} NAME_WE)

    list(APPEND PROTO_SRC "${CMAKE_SOURCE_DIR}/resource/${PREFIX}.pb.cc")
    list(APPEND PROTO_HEADER "${CMAKE_SOURCE_DIR}/resource/${PREFIX}.pb.h")
endforeach()


include_directories(
    ${CMAKE_SOURCE_DIR}/resource
)

set(SRC
   # proto接口
   ${PROTO_SRC}
)

# 定义可执行文件列表
set(EXECUTABLES
    nameserver
    broker
    producer
    consumer
    admin
)

# 使用 foreach 循环添加可执行文件
foreach(executable IN LISTS EXECUTABLES)
    add_executable(${executable} ${executable}.cpp ${SRC})
    target_link_libraries(${executable} ${LIBS} zeroplusmq)
    install(TARGETS ${executable} DESTINATION bin)
    set_target_properties(${executable} PROPERTIES INSTALL_RPATH "/usr/lib:${CMAKE_INSTALL_PREFIX}/lib")
endforeach()
